package com.touchalachs.core;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;


public class ScrollingBackground  implements Drawable, Updatable{
	
	private float speed = 20;
	private final Bitmap bitmap;
	private volatile int pos;

	public ScrollingBackground(Point screnSize, Bitmap bitmap) {
		pos = 0;
		this.bitmap = Bitmap.createScaledBitmap(bitmap, screnSize.x, screnSize.y, false);
	}
	
	public ScrollingBackground(Point screnSize, Bitmap bitmap, float speed) {
		this(screnSize, bitmap);
		this.speed = speed;
	}

	@Override
	public void update(float deltaSec) {
		pos += deltaSec*speed;
		if (pos >= bitmap.getHeight()){
			pos -= bitmap.getHeight();
		}
	}

	@Override
	public void draw(Canvas canvas) {
		canvas.drawBitmap(bitmap, 0, pos, null);
		canvas.drawBitmap(bitmap, 0, pos-bitmap.getHeight(), null);
	}
}
